#include"DictServer.hpp"
#include"Dictionary.hpp"
#include<iostream>
#include<memory>

void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " localport" << std::endl;
}

// //for debug
// std::string func(const std::string& word,const std::string whoip,uint16_t whoport)
// {
//     return "hello";
// }

int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        Usage(argv[0]);
        exit(0);
    }

    EnableConsoleLogStrategy();
    Dictionary dict("./dict.txt");
    uint16_t port=std::stoi(argv[1]);
    std::unique_ptr<DictServer> usp=std::make_unique<DictServer>(port,
        [&dict](const std::string& word,const std::string &whoip,uint16_t whoport)->std::string{
            return dict.Translate(word,whoip,whoport);
        }
    );
    usp->Init();
    usp->Start();
    return 0;
}